package com.rpoonolly.simplegame.mapio.jsoncoders;

import java.io.IOException;

import org.json.simple.JSONObject;

import com.rpoonolly.simplegame.core.aabb.AABBEntity;
import com.rpoonolly.simplegame.core.aabb.DynamicAABBEntity;

public class DynamicAABBentityJSONCoder extends JSONCoder<DynamicAABBEntity>{
	private static DynamicAABBentityJSONCoder singletonInstance;
	private AABBEntityJSONCoder aabbEntCoder = AABBEntityJSONCoder.getInstance();

	private DynamicAABBentityJSONCoder() {}

	public static DynamicAABBentityJSONCoder getInstance() {
		if (singletonInstance == null) {
			singletonInstance = new DynamicAABBentityJSONCoder();
		}

		return singletonInstance;
	}

	@Override
	public JSONObject encode(DynamicAABBEntity obj) throws IOException {
		return aabbEntCoder.encode(obj);
	}

	@Override
	public DynamicAABBEntity decode(JSONObject code) throws IOException {
		AABBEntity ent = aabbEntCoder.decode(code);
		return new DynamicAABBEntity(ent.getX(), ent.getY(), ent.getWidth(), ent.getHeight());
	}
}
